//
//  ComposeToolBar.swift
//  Weibo
//
//  Created by 郑克哥哥 on 2017/8/14.
//  Copyright © 2017年 郑克哥哥. All rights reserved.
//

import UIKit

//工具条
class ComposeToolBar: UIStackView {
    
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加子控件
    private func setupUI(){
        //水平方向
        self.axis = .horizontal
        //设置按钮间距
        self.distribution = .fillEqually
        
        
        addChildButton(imageName: "compose_toolbar_picture")
        addChildButton(imageName: "compose_mentionbutton_background")
        addChildButton(imageName: "compose_trendbutton_background")
        addChildButton(imageName: "compose_emoticonbutton_background")
        addChildButton(imageName: "compose_add_background")
        
    }
    
    //创建添加子按钮
    private func addChildButton(imageName: String){
        
        let button = UIButton()
        //设置图片
        button.setImage(UIImage(named:imageName), for: .normal)
        button.setImage(UIImage(named:"\(imageName)_highlighted"), for: .highlighted)
        button.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
        //设置toolBar背景图片
        button.setBackgroundImage(UIImage(named:"compose_toolbar_background"), for: .normal)
        //取消点击图片的 高亮效果
        button.adjustsImageWhenHighlighted = false
        //添加按钮
        addArrangedSubview(button)
    }

    //按钮点击方法
    @objc private func clickButton(){
        
        print("点按钮")
        
    }
}
